package org.video.mine.mycode;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DownTask {
    public static List<DownThread> downThreadList;
    public static ExecutorService sExe = Executors.newCachedThreadPool();//线程池

    public static void startDown(int position){
        if (downThreadList!=null){
            downThreadList.get(position).isLoading = true;
            sExe.execute(downThreadList.get(position));
        }
    }

    public static void stopAll(){
        sExe.shutdownNow();
    }

    public static void removeList(String name,String set){
        for (DownThread downThread:downThreadList){
            if (downThread.name.equals(name) && downThread.set.equals(set)){
                downThreadList.remove(downThread);
                break;
            }
        }
    }

    public static void stopThread(String name, String set){
        for (DownThread downThread:downThreadList){
            if (downThread.name.equals(name) && downThread.set.equals(set) && downThread.isLoading){
                downThread.isLoading = false;
                break;
            }
        }
    }

    public static void startThread(String name, String set){
        for (DownThread downThread:downThreadList){
            if (downThread.name.equals(name) && downThread.set.equals(set) && !downThread.isLoading){
                downThread.isLoading = true;
                sExe.execute(downThread);
                break;
            }
        }
    }

    public static void loadReady(String name, String set) {
        for (DownThread downThread:downThreadList){
            if (downThread.name.equals(name) && downThread.set.equals(set)){
                downThreadList.remove(downThread);
                break;
            }
        }
    }
}
